package com.StarStudio.Utils;

import org.apache.commons.codec.binary.Base64;

import java.io.IOException;

public class Base64Tool {
    /**
     * 字节数组转Base64编码
     */
    public static String byteToBase64(byte[] bytes) {
        return new String(Base64.encodeBase64(bytes));
    }


    /**
     * Base64编码转字节数组
     */
    public static byte[] base64ToByte(String base64Key) throws IOException {
        return Base64.decodeBase64(base64Key);
    }

    public static void main(String[] args) throws Exception {
        String[] keyPairArr = RSAUtil.genKeyPair();
        System.out.println("公钥: " + keyPairArr[0]);
        System.out.println();

        //
        System.out.println("私钥: " + keyPairArr[1]);
        System.out.println();

        //
        String string = "{\"user\":\"188725\",\"cash\":2,\"order_id\":\"1654776853869006848\",\"act_id\":\"ybApp\",\"task\":\"test\"}";

        String msg = RSAUtil.publicEncrypt(string, keyPairArr[0]);
        System.out.println("加密后内容: " + msg);
        System.out.println();

        //
        String mms = RSAUtil.privateDecrypt(msg, keyPairArr[1]);
        System.out.println("解密后内容: " + mms);
        System.out.println();

    }

}



